<?php
namespace app\api\controller;
use think\Db;
use app\admin\model\Config;
use app\common\model\School as SchoolModel;
use app\common\service\GuguService;
use app\common\service\ZhiyuanService;

//志愿填报 智能填报
class ZhiyuanNew extends App
{
    //填报志愿
    public function get_school_list()
    {
        //$start_time = microtime(true);//计时

        $user_id = $this->user_id;
        $province_id = $this->province_id;
        $pagesize = 10;
        $page = $this->request->get("page",1,'intval');
        $level = $this->request->get("level",0,'intval');
        $batch= $this->request->get("batch",1,'intval');
        if(empty($batch)){
            return $this->show(2001,"缺少参数batch!", '');
        }
        $member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title,cj_rank,cj_subject_mode_title_2024,cj_subject_mode_title_2023')->where('id',$user_id)->find();
        if(empty($member['cj_rank'])){
            return $this->show(2001,"请先创建成绩", '');
        }
        $type = $type1 = $type2= $member['cj_subject_mode_title'];

        $score_min = $this->request->get("score_min",0,'intval');
        $score_max = $this->request->get("score_max",0,'intval');
        $province_ids= $this->request->get("province_ids",'','trim');
        $school_type= $this->request->get("school_type",'','trim');
        $school_tese= $this->request->get("school_tese",'','trim');
        $school_xingzhi= $this->request->get("school_xingzhi",'','trim');
        $school_ids_1= $this->request->get("school_ids",'','trim');
        $cate_ids = $this->request->get("cate_ids",'','trim');
        $major_ids = $this->request->get("major_ids",'','trim');


        if(empty($score_min)){
            $score_min = $member['cj_score']-30;
        }
        if(empty($score_max)){
            $score_max = $member['cj_score']+20;
        }
        if($score_min<$member['cj_score']-50){
            return $this->show(2001,"最低分".($member['cj_score']-50), '');
        }
        if($score_max>$member['cj_score']+50){
            return $this->show(2001,"最高分".($member['cj_score']+50), '');
        }


        $major_ids1 = [];
        $major_ids = explode(',',$major_ids);
        if(!empty($cate_ids)){
            $major_ids1 = Db::name("major")->where('cate_level',3)->where('cate_pid','in',$cate_ids)->column('id');
        }
        $major_ids = array_filter(array_unique(array_merge($major_ids,$major_ids1)));
        $major_school_ids = [];
        if(!empty($major_ids)){
            foreach($major_ids as $km=>$vm){
                $major_school_id = Db::name('school_major_data')->where('FIND_IN_SET(:id,major_ids)',['id' => $vm])->column('school_id');
                $major_school_ids = array_merge($major_school_ids,$major_school_id);

            }
        }
        //dump($major_ids);die;

        if(!empty($province_ids)){
            $map['province_id'] = ['in',$province_ids];
        }
        if(!empty($school_type)){
            $school_id1 = Db::name('school')->where('school_type','in',$school_type)->column('id');
        }else{
            $school_id1 = Db::name('school')->column('id');
        }
        if(!empty($school_tese)){
            $school_id2 = Db::name('school_tese_data')->where('tese_id','in',$school_tese)->column('school_id');
        }else{
            $school_id2 = Db::name('school')->column('id');
        }
        if(!empty($school_xingzhi)){
            $school_id3 = Db::name('school')->where('school_xingzhi','in',$school_xingzhi)->column('id');
        }else{
            $school_id3 = Db::name('school')->column('id');
        }
        $school_ids = array_intersect($school_id1,$school_id2,$school_id3);
        if(!empty($major_school_ids)){
            $school_ids = array_intersect($school_ids,$major_school_ids);
        }

        $map['id'] = ['in',$school_ids];
        $map['status'] = 1;
        $school_ids_ed = Db::name("school")->where($map)->column('id');
        if(!empty($school_ids_1)){
            $school_ids_1 = explode(',',$school_ids_1);
            $school_ids_ed = array_filter(array_unique(array_merge($school_ids_ed,$school_ids_1)));
        }
        $school_list = Db::name("school")->where('id','in',$school_ids_ed)->field('school_uuid,id,school_suoshu,college_code,school_type')->select();
        $school_uuids_ed = array_column($school_list,'school_uuid');

        if($batch == 1){
            $batchname = SchoolModel::getBenkeBtachs();
            $batch_score_name = '本科,本二,1段';
        }elseif($batch == 2){
            $batchname = SchoolModel::getZhuankeBtachs();
            $batch_score_name = '专科,2段';
        }else{
            return $this->show(2001,"参数batch错误!", '');
        }
        /*$year = date('Y',strtotime("-1 year"));
        $year1 = date('Y',strtotime("-2 year"));
        $year2 = date('Y',strtotime("-3 year"));
        if($year < 2025){
            $type = $member['cj_subject_mode_title_2024'];
        }
        if($year1 < 2024){
            $type1 = $member['cj_subject_mode_title_2023'];
        }
        if($year2 < 2024){
            $type2 = $member['cj_subject_mode_title_2023'];
        } */
        $year = date('Y');
        $year1 = date('Y',strtotime("-1 year"));
        $year2 = date('Y',strtotime("-2 year"));
        if($year < 2026){
            $type = $member['cj_subject_mode_title_2024'];
        }
        if($year1 < 2025){
            $type1 = $member['cj_subject_mode_title_2023'];
        }
        if($year2 < 2025){
            $type2 = $member['cj_subject_mode_title_2023'];
        }

        $batch_score = Db::name("batch_line")->where('batch_name','in',$batch_score_name)->where('province_id',$province_id)->where('year',$year)->value('socre');//批次分数
        $batch_score1 = Db::name("batch_line")->where('batch_name','in',$batch_score_name)->where('province_id',$province_id)->where('year',$year1)->value('socre');//批次分数
        $batch_score2 = Db::name("batch_line")->where('batch_name','in',$batch_score_name)->where('province_id',$province_id)->where('year',$year2)->value('socre');//批次分数


        if(cache('school_'.$user_id)){
            $data = cache('school_'.$user_id);
        }else{
            //$data = $this->get_data_cache($user_id,$province_id);

            $result = ZhiyuanService::get_data_cache1($user_id,$province_id);
            if($result[0] != 200){
                return $this->show(2002,$result[1]??'error', '');
            }
            $data = $result[1];

            Cache('school_'.$user_id,$data);
        }

        foreach($data as $k=>$v){
            if(!in_array($v['school_uuid'],$school_uuids_ed)){
                unset($data[$k]);
                continue;
            }
            $batchnames = explode(',',$batchname);
            if(!in_array($v['admission_batch'],$batchnames)){
                unset($data[$k]);
                continue;
            }
            if(!empty($score_min)){
                if($v['score_min']<$score_min-1){
                    unset($data[$k]);
                    continue;
                }
            }
            if(!empty($score_max)){
                if($v['score_min']>$score_max+1){
                    unset($data[$k]);
                    continue;
                }
            }
            //院校线差
            /*if(empty($batch_score)){
                $linecha_s = '-';
            }else{
                if(!empty($v['score_min']) && is_numeric($v['score_min'])){
                    $linecha_s = $v['score_min']-$batch_score;
                }else{
                    $linecha_s = '-';
                }
            }
            if(empty($batch_score1)){
                $linecha_s1 = '-';
            }else{
                if(!empty($v['score_min_1']) && is_numeric($v['score_min_1'])){
                    $linecha_s1 = $v['score_min_1']-$batch_score1;
                }else{
                    $linecha_s1 = '-';
                }
            }
            if(empty($batch_score2)){
                $linecha_s2 = '-';
            }else{
                if(!empty($v['score_min_2']) && is_numeric($v['score_min_2'])){
                    $linecha_s2 = $v['score_min_2']-$batch_score2;
                }else{
                    $linecha_s2 = '-';
                }
            }
            $data[$k]['linecha_1'] = $linecha_s1;
            $data[$k]['linecha_2'] = $linecha_s2;*/

            $major_list = $v['major_list'];
            foreach($major_list as $km=>$vm){
                if(!in_array($vm['batch_name'],$batchnames)){
                    unset($major_list[$km]);
                    continue;
                }
                //专业线差
                /*if(empty($batch_score)){
                    $linecha = '-';
                }else{
                    if(!empty($vm['score_min']) && is_numeric($vm['score_min'])){
                        $linecha = $vm['score_min']-$batch_score;
                    }else{
                        $linecha = '-';
                    }
                }
                $major_list[$km]['linecha'] = $linecha;*/
            }
            /*if(empty($major_list)){
                unset($data[$k]);
                continue;
            }*/
            $data[$k]['major_list'] = $major_list;
        }

        $all_nums = 0;
        $chong_nums = 0;
        $wen_nums = 0;
        $bao_nums = 0;
        $data_level = [];
        foreach($data as $k=>$v){
            $dengxiao_weicha = $v['dengxiao_weicha'];
            if($dengxiao_weicha>4000){//大于75%
                $bao_nums++;
                if($level==3){
                    $data_level[] = $v;
                }
            }elseif($dengxiao_weicha>-1 && $dengxiao_weicha<=4000){//大于46%,小于等于75%，
                $wen_nums++;
                if($level==2){
                    $data_level[] = $v;
                }
            }else{
                $chong_nums++;
                if($level==1){
                    $data_level[] = $v;
                }
            }
            $all_nums++;
        }
        $level_nums = array('all_nums'=>$all_nums,'chong_nums'=>$chong_nums,'wen_nums'=>$wen_nums,'bao_nums'=>$bao_nums);

        if($level>0){
            $data = $data_level;
        }

        $count = count($data);
        $pages = ceil($count/$pagesize);
        $start = ($page - 1) * $pagesize;
        $list = array_slice($data, $start, $pagesize);

        //对当前页10条数据进行处理
        //23年院校数据
        $school_uuids = array_column($list,'school_uuid');
        //dump($school_uuids);die;
        //$score_min = $member['cj_score']-50;
        //$score_max = $member['cj_score']+50;
        /*$list_1 = Db::name("school_line_new")->where('province_id',$province_id)->where('year',$year1)->where('type_name',$type1)->where('school_uuid','in',$school_uuids)->where('admission_batch','in', $batchname)->where('lowest_rank','>',0)->field('school_uuid,lowest_score as score_min,lowest_rank as weici_min,course_selection_name as subject_group,admission_batch,year')->order('id asc')->select();*/

        $list_1 = Db::name("school_line_new")->where('province_id',$province_id)->where('school_uuid','in',$school_uuids)->where('admission_batch','in', $batchname)->where('lowest_rank','>',0)->field('school_uuid,lowest_score as score_min,lowest_rank as weici_min,course_selection_name as subject_group,admission_batch,year')->order('id asc')->select();
        //echo Db::name("school_line_new")->getlastsql();die;
        $list_1_new = $list_1_new_1 = [];
        foreach($list_1 as $k=>$v){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($v['weici_min']) && is_numeric($v['weici_min'])){
                    $dengxiao_weicha = $v['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }
            //院校线差
            if(empty($batch_score1)){
                $linecha_s1 = '-';
            }else{
                if(!empty($v['score_min']) && is_numeric($v['score_min'])){
                    $linecha_s1 = $v['score_min']-$batch_score1;
                }else{
                    $linecha_s1 = '-';
                }
            }

            //$list_1[$k]['dengxiao_weicha'] = $dengxiao_weicha;
            $v['dengxiao_weicha'] = $dengxiao_weicha;
            $v['linecha'] = $linecha_s1;
            if(!empty($v['subject_group'])){
                $v['subject_group'] = filter_subject_group($v['subject_group']);
            }
            $list_1_new[$v['school_uuid'].$v['admission_batch'].$v['subject_group'].$v['year']] = $v;
            $list_1_new_1[$v['school_uuid'].$v['year']] = $v;
        }

        //dump($list);
        //dump($list_1_new_1); die;
        /*	//22年院校数据
            $list_2 = Db::name("school_line_new")->where('province_id',$province_id)->where('year',$year2)->where('type_name',$type2)->where('school_uuid','in',$school_uuids)->where('admission_batch','in', $batchname)->where('lowest_rank','>',0)->field('school_uuid,lowest_score as score_min,lowest_rank as weici_min,course_selection_name as subject_group,admission_batch')->order('id asc')->select();
            $list_2_new = $list_2_new_2 = [];
            foreach($list_2 as $k=>$v){
                if(empty($member['cj_rank'])){
                    $dengxiao_weicha = '-';
                }else{
                    if(!empty($v['weici_min']) && is_numeric($v['weici_min'])){
                        $dengxiao_weicha = $v['weici_min']-$member['cj_rank'];
                    }else{
                        $dengxiao_weicha = '-';
                    }
                }
                //院校线差
                if(empty($batch_score2)){
                    $linecha_s2 = '-';
                }else{
                    if(!empty($v['score_min']) && is_numeric($v['score_min'])){
                        $linecha_s2 = $v['score_min']-$batch_score2;
                    }else{
                        $linecha_s2 = '-';
                    }
                }
                //$list_2[$k]['dengxiao_weicha'] = $dengxiao_weicha;
                $v['dengxiao_weicha'] = $dengxiao_weicha;
                $v['linecha'] = $linecha_s2;
                if(!empty($v['subject_group'])){
                    $v['subject_group'] = filter_subject_group($v['subject_group']);
                }
                $list_2_new[$v['school_uuid'].$v['admission_batch'].$v['subject_group']] = $v;
                $list_2_new_2[$v['school_uuid']] = $v;
            }*/



        //23年专业数据
        $major_list_1 = Db::name("major_line_new")->where('province_id',$province_id)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group,year,major_standard_code')->order('id asc')->select();

        //23年招生计划
        $plan_list_1 = Db::name("school_plan_new")->where('province_id',$province_id)->where('school_uuid','in',$school_uuids)->where('enrollment_numbers','>',0)->field('school_uuid,school_name,college_major_code,college_major_name,enrollment_numbers,year')->order('id asc')->select();
        $plan_list_new_1 = [];
        foreach($plan_list_1 as $kp=>$vp){
            $plan_list_new_1[$vp['school_uuid'].$vp['year']][] = $vp;
        }//dump($plan_list_new_1);die;
        $major_list_new_1 = [];
        foreach($major_list_1 as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }
            if(empty($batch_score)){
                $linecha = '-';
            }else{
                if(!empty($vm['score_min']) && is_numeric($vm['score_min'])){
                    $linecha = $vm['score_min']-$batch_score;
                }else{
                    $linecha = '-';
                }
            }
            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = $linecha;
            $vm['plan_nums'] = '-';
            $major_list_new_1[$vm['school_uuid'].$vm['year']][] = $vm;
        }


        foreach($list as $kt=>$vt){
            //去年院校线差
            if(empty($batch_score)){
                $linecha_s = '-';
            }else{
                if(!empty($vt['score_min']) && is_numeric($vt['score_min'])){
                    $linecha_s = $vt['score_min']-$batch_score;
                }else{
                    $linecha_s = '-';
                }
            }
            $list[$kt]['linecha'] = $linecha_s;
            //匹配23年院校数据
            if(!empty($vt['subject_group'])){
                $vt['subject_group'] = filter_subject_group($vt['subject_group']);
            }
            if(!empty($list_1_new[$vt['school_uuid'].$vt['admission_batch'].$vt['subject_group'].$year1])){
                $school_new_1 = $list_1_new[$vt['school_uuid'].$vt['admission_batch'].$vt['subject_group'].$year1];
            }else{
                if(!empty($list_1_new_1[$vt['school_uuid'].$year1])){
                    $school_new_1 = $list_1_new_1[$vt['school_uuid'].$year1];
                }else{
                    $school_new_1 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                }
            }

            //匹配22年院校数据
            if(!empty($list_1_new[$vt['school_uuid'].$vt['admission_batch'].$vt['subject_group'].$year2])){
                $school_new_2 = $list_1_new[$vt['school_uuid'].$vt['admission_batch'].$vt['subject_group'].$year2];
            }else{
                if(!empty($list_1_new_1[$vt['school_uuid'].$year2])){
                    $school_new_2 = $list_1_new_1[$vt['school_uuid'].$year2];
                }else{
                    $school_new_2 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                }
            }
            $list[$kt]['score_min_1'] = $school_new_1['score_min']??'-';
            $list[$kt]['weici_min_1'] = $school_new_1['weici_min']??'-';
            $list[$kt]['linecha_1'] = $school_new_1['linecha']??'-';
            $list[$kt]['dengxiao_weicha_1'] = $school_new_1['dengxiao_weicha']??'-';
            $list[$kt]['score_min_2'] = $school_new_2['score_min']??'-';
            $list[$kt]['weici_min_2'] = $school_new_2['weici_min']??'-';
            $list[$kt]['linecha_2'] = $school_new_2['linecha']??'-';
            $list[$kt]['dengxiao_weicha_2'] = $school_new_2['dengxiao_weicha']??'-';
            //dump($list[$kt]);die;
            //处理专业
            foreach($list[$kt]['major_list'] as $km=>$vm){
                /*//匹配去年专业招生计划
                $plan_list_new_tem = !empty($plan_list_new[$vt['school_uuid']])?$plan_list_new[$vt['school_uuid']]:[];
                $list[$kt]['major_list'][$km]['plan_nums'] = search_plan_like_major($plan_list_new_tem,$vm['major_name'],$vt['school_uuid']);*/
                //计算去年专业线差
                /*if(empty($batch_score)){
                    $linecha = '-';
                }else{
                    if(!empty($vm['score_min']) && is_numeric($vm['score_min'])){
                        $linecha = $vm['score_min']-$batch_score;
                    }else{
                        $linecha = '-';
                    }
                }
                $list[$kt]['major_list'][$km]['linecha'] = $linecha;*/

                //匹配去年专业数据
                $marjor_new_0 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                if(!empty($major_list_new_1[$vt['school_uuid'].$year])){
                    $marjor_new_0 = search_major_like($major_list_new_1[$vt['school_uuid'].$year],$vm['major_name']);
                }
                $list[$kt]['major_list'][$km]['score_min'] = $marjor_new_0['score_min'];
                $list[$kt]['major_list'][$km]['weici_min'] = $marjor_new_0['weici_min'];
                $list[$kt]['major_list'][$km]['dengxiao_weicha'] = $marjor_new_0['dengxiao_weicha'];
                $list[$kt]['major_list'][$km]['linecha'] = $marjor_new_0['linecha'];


                //匹配23年专业数据
                $marjor_new_1 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                if(!empty($major_list_new_1[$vt['school_uuid'].$year1])){
                    $marjor_new_1 = search_major_like($major_list_new_1[$vt['school_uuid'].$year1],$vm['major_name']);
                }
                //匹配23年计划
                $plan_list_new_tem_1 = !empty($plan_list_new_1[$vt['school_uuid'].$year1])?$plan_list_new_1[$vt['school_uuid'].$year1]:[];
                $marjor_new_1['plan_nums'] = search_plan_like_major($plan_list_new_tem_1,$vm['major_name'],$vt['school_uuid']);
                $list[$kt]['major_list'][$km]['score_min_1'] = $marjor_new_1['score_min'];
                $list[$kt]['major_list'][$km]['weici_min_1'] = $marjor_new_1['weici_min'];
                $list[$kt]['major_list'][$km]['dengxiao_weicha_1'] = $marjor_new_1['dengxiao_weicha'];
                $list[$kt]['major_list'][$km]['linecha_1'] = $marjor_new_1['linecha'];
                $list[$kt]['major_list'][$km]['plan_nums_1'] = $marjor_new_1['plan_nums']??'-';

                //匹配22年专业数据
                $marjor_new_2 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                if(!empty($major_list_new_1[$vt['school_uuid'].$year2])){
                    $marjor_new_2 = search_major_like($major_list_new_1[$vt['school_uuid'].$year2],$vm['major_name']);
                }
                //匹配22年计划
                $plan_list_new_tem_2 = !empty($plan_list_new_1[$vt['school_uuid'].$year2])?$plan_list_new_1[$vt['school_uuid'].$year2]:[];
                $marjor_new_2['plan_nums'] = search_plan_like_major($plan_list_new_tem_2,$vm['major_name'],$vm['school_uuid']);
                $list[$kt]['major_list'][$km]['score_min_2'] = $marjor_new_2['score_min'];
                $list[$kt]['major_list'][$km]['weici_min_2'] = $marjor_new_2['weici_min'];
                $list[$kt]['major_list'][$km]['dengxiao_weicha_2'] = $marjor_new_2['dengxiao_weicha'];
                $list[$kt]['major_list'][$km]['linecha_2'] = $marjor_new_2['linecha'];
                $list[$kt]['major_list'][$km]['plan_nums_2'] = $marjor_new_2['plan_nums']??'-';



            }

        }
        //dump($list);die;
        $data = array('level_nums'=>$level_nums,'list'=>$list,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);
        //return $this->show(1,"成功", $data);

        Cache('level_nums_'.$user_id,$level_nums);
        return $this->return_json(1,"成功", $data);

    }
    //填报志愿
    public function get_school_list1()
    {
        //$start_time = microtime(true);//计时

        $user_id = $this->user_id;
        $province_id = $this->province_id;
        $pagesize = 10;
        $page = $this->request->get("page",1,'intval');
        $level = $this->request->get("level",0,'intval');
        $batch= $this->request->get("batch",1,'intval');
        if(empty($batch)){
            return $this->show(2001,"缺少参数batch!", '');
        }
        $member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title,cj_rank,cj_subject_mode_title_2024,cj_subject_mode_title_2023')->where('id',$user_id)->find();
        if(empty($member['cj_rank'])){
            return $this->show(2001,"请先创建成绩", '');
        }
        $type = $type1 = $type2= $member['cj_subject_mode_title'];

        $score_min = $this->request->get("score_min",0,'intval');
        $score_max = $this->request->get("score_max",0,'intval');
        $province_ids= $this->request->get("province_ids",'','trim');
        $school_type= $this->request->get("school_type",'','trim');
        $school_tese= $this->request->get("school_tese",'','trim');
        $school_xingzhi= $this->request->get("school_xingzhi",'','trim');
        $school_ids_1= $this->request->get("school_ids",'','trim');
        $cate_ids = $this->request->get("cate_ids",'','trim');
        $major_ids = $this->request->get("major_ids",'','trim');


        if(empty($score_min)){
            $score_min = $member['cj_score']-30;
        }
        if(empty($score_max)){
            $score_max = $member['cj_score']+20;
        }
        if($score_min<$member['cj_score']-50){
            return $this->show(2001,"最低分".($member['cj_score']-50), '');
        }
        if($score_max>$member['cj_score']+50){
            return $this->show(2001,"最高分".($member['cj_score']+50), '');
        }


        $major_ids1 = [];
        $major_ids = explode(',',$major_ids);
        if(!empty($cate_ids)){
            $major_ids1 = Db::name("major")->where('cate_level',3)->where('cate_pid','in',$cate_ids)->column('id');
        }
        $major_ids = array_filter(array_unique(array_merge($major_ids,$major_ids1)));
        $major_school_ids = [];
        if(!empty($major_ids)){
            foreach($major_ids as $km=>$vm){
                $major_school_id = Db::name('school_major_data')->where('FIND_IN_SET(:id,major_ids)',['id' => $vm])->column('school_id');
                $major_school_ids = array_merge($major_school_ids,$major_school_id);

            }
        }
        //dump($major_ids);die;

        if(!empty($province_ids)){
            $map['province_id'] = ['in',$province_ids];
        }
        if(!empty($school_type)){
            $school_id1 = Db::name('school')->where('school_type','in',$school_type)->column('id');
        }else{
            $school_id1 = Db::name('school')->column('id');
        }
        if(!empty($school_tese)){
            $school_id2 = Db::name('school_tese_data')->where('tese_id','in',$school_tese)->column('school_id');
        }else{
            $school_id2 = Db::name('school')->column('id');
        }
        if(!empty($school_xingzhi)){
            $school_id3 = Db::name('school')->where('school_xingzhi','in',$school_xingzhi)->column('id');
        }else{
            $school_id3 = Db::name('school')->column('id');
        }
        $school_ids = array_intersect($school_id1,$school_id2,$school_id3);
        if(!empty($major_school_ids)){
            $school_ids = array_intersect($school_ids,$major_school_ids);
        }

        $map['id'] = ['in',$school_ids];
        $map['status'] = 1;
        $school_ids_ed = Db::name("school")->where($map)->column('id');
        if(!empty($school_ids_1)){
            $school_ids_1 = explode(',',$school_ids_1);
            $school_ids_ed = array_filter(array_unique(array_merge($school_ids_ed,$school_ids_1)));
        }
        $school_list = Db::name("school")->where('id','in',$school_ids_ed)->field('school_uuid,id,school_suoshu,college_code,school_type')->select();
        $school_uuids_ed = array_column($school_list,'school_uuid');

        if($batch == 1){
            $batchname = SchoolModel::getBenkeBtachs();
            $batch_score_name = '本科,本二,1段';
        }elseif($batch == 2){
            $batchname = SchoolModel::getZhuankeBtachs();
            $batch_score_name = '专科,2段';
        }else{
            return $this->show(2001,"参数batch错误!", '');
        }
        /*$year = date('Y',strtotime("-1 year"));
        $year1 = date('Y',strtotime("-2 year"));
        $year2 = date('Y',strtotime("-3 year"));
        if($year < 2025){
            $type = $member['cj_subject_mode_title_2024'];
        }
        if($year1 < 2024){
            $type1 = $member['cj_subject_mode_title_2023'];
        }
        if($year2 < 2024){
            $type2 = $member['cj_subject_mode_title_2023'];
        } */
        $year = date('Y');
        $year1 = date('Y',strtotime("-1 year"));
        $year2 = date('Y',strtotime("-2 year"));
        if($year < 2026){
            $type = $member['cj_subject_mode_title_2024'];
        }
        if($year1 < 2025){
            $type1 = $member['cj_subject_mode_title_2023'];
        }
        if($year2 < 2025){
            $type2 = $member['cj_subject_mode_title_2023'];
        }

        $batch_score = Db::name("batch_line")->where('batch_name','in',$batch_score_name)->where('province_id',$province_id)->where('year',$year)->value('socre');//批次分数
        $batch_score1 = Db::name("batch_line")->where('batch_name','in',$batch_score_name)->where('province_id',$province_id)->where('year',$year1)->value('socre');//批次分数
        $batch_score2 = Db::name("batch_line")->where('batch_name','in',$batch_score_name)->where('province_id',$province_id)->where('year',$year2)->value('socre');//批次分数


        if(cache('school_'.$user_id)){
            $data = cache('school_'.$user_id);
        }else{
            //$data = $this->get_data_cache($user_id,$province_id);

            $result = ZhiyuanService::get_data_cache($user_id,$province_id);
            if($result[0] != 200){
                return $this->show(2002,$result[1]??'error', '');
            }
            $data = $result[1];

            Cache('school_'.$user_id,$data);
        }

        foreach($data as $k=>$v){
            if(!in_array($v['school_uuid'],$school_uuids_ed)){
                unset($data[$k]);
                continue;
            }
            $batchnames = explode(',',$batchname);
            if(!in_array($v['admission_batch'],$batchnames)){
                unset($data[$k]);
                continue;
            }
            if(!empty($score_min)){
                if($v['score_min']<$score_min-1){
                    unset($data[$k]);
                    continue;
                }
            }
            if(!empty($score_max)){
                if($v['score_min']>$score_max+1){
                    unset($data[$k]);
                    continue;
                }
            }
            //院校线差
            /*if(empty($batch_score)){
                $linecha_s = '-';
            }else{
                if(!empty($v['score_min']) && is_numeric($v['score_min'])){
                    $linecha_s = $v['score_min']-$batch_score;
                }else{
                    $linecha_s = '-';
                }
            }
            if(empty($batch_score1)){
                $linecha_s1 = '-';
            }else{
                if(!empty($v['score_min_1']) && is_numeric($v['score_min_1'])){
                    $linecha_s1 = $v['score_min_1']-$batch_score1;
                }else{
                    $linecha_s1 = '-';
                }
            }
            if(empty($batch_score2)){
                $linecha_s2 = '-';
            }else{
                if(!empty($v['score_min_2']) && is_numeric($v['score_min_2'])){
                    $linecha_s2 = $v['score_min_2']-$batch_score2;
                }else{
                    $linecha_s2 = '-';
                }
            }
            $data[$k]['linecha_1'] = $linecha_s1;
            $data[$k]['linecha_2'] = $linecha_s2;*/

            $major_list = $v['major_list'];
            foreach($major_list as $km=>$vm){
                if(!in_array($vm['batch_name'],$batchnames)){
                    unset($major_list[$km]);
                    continue;
                }
                //专业线差
                /*if(empty($batch_score)){
                    $linecha = '-';
                }else{
                    if(!empty($vm['score_min']) && is_numeric($vm['score_min'])){
                        $linecha = $vm['score_min']-$batch_score;
                    }else{
                        $linecha = '-';
                    }
                }
                $major_list[$km]['linecha'] = $linecha;*/
            }
            /*if(empty($major_list)){
                unset($data[$k]);
                continue;
            }*/
            $data[$k]['major_list'] = $major_list;
        }

        $all_nums = 0;
        $chong_nums = 0;
        $wen_nums = 0;
        $bao_nums = 0;
        $data_level = [];
        foreach($data as $k=>$v){
            $dengxiao_weicha = $v['dengxiao_weicha'];
            if($dengxiao_weicha>4000){//大于75%
                $bao_nums++;
                if($level==3){
                    $data_level[] = $v;
                }
            }elseif($dengxiao_weicha>-1 && $dengxiao_weicha<=4000){//大于46%,小于等于75%，
                $wen_nums++;
                if($level==2){
                    $data_level[] = $v;
                }
            }else{
                $chong_nums++;
                if($level==1){
                    $data_level[] = $v;
                }
            }
            $all_nums++;
        }
        $level_nums = array('all_nums'=>$all_nums,'chong_nums'=>$chong_nums,'wen_nums'=>$wen_nums,'bao_nums'=>$bao_nums);

        if($level>0){
            $data = $data_level;
        }

        $count = count($data);
        $pages = ceil($count/$pagesize);
        $start = ($page - 1) * $pagesize;
        $list = array_slice($data, $start, $pagesize);

        //对当前页10条数据进行处理
        //23年院校数据
        $school_uuids = array_column($list,'school_uuid');
        //dump($school_uuids);
        //$score_min = $member['cj_score']-50;
        //$score_max = $member['cj_score']+50;
        $list_1 = Db::name("school_line_new")->where('province_id',$province_id)->where('year',$year1)->where('type_name',$type1)->where('school_uuid','in',$school_uuids)->where('admission_batch','in', $batchname)->where('lowest_rank','>',0)->field('school_uuid,lowest_score as score_min,lowest_rank as weici_min,course_selection_name as subject_group,admission_batch')->order('id asc')->select();
        //echo Db::name("school_line_new")->getlastsql();die;
        $list_1_new = $list_1_new_1 = [];
        foreach($list_1 as $k=>$v){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($v['weici_min']) && is_numeric($v['weici_min'])){
                    $dengxiao_weicha = $v['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }
            //院校线差
            if(empty($batch_score1)){
                $linecha_s1 = '-';
            }else{
                if(!empty($v['score_min']) && is_numeric($v['score_min'])){
                    $linecha_s1 = $v['score_min']-$batch_score1;
                }else{
                    $linecha_s1 = '-';
                }
            }
            //$list_1[$k]['dengxiao_weicha'] = $dengxiao_weicha;
            $v['dengxiao_weicha'] = $dengxiao_weicha;
            $v['linecha'] = $linecha_s1;
            if(!empty($v['subject_group'])){
                $v['subject_group'] = filter_subject_group($v['subject_group']);
            }
            $list_1_new[$v['school_uuid'].$v['admission_batch'].$v['subject_group']] = $v;
            $list_1_new_1[$v['school_uuid']] = $v;
        }

        //dump($list);
        //dump($list_1_new); die;
        //22年院校数据
        $list_2 = Db::name("school_line_new")->where('province_id',$province_id)->where('year',$year2)->where('type_name',$type2)->where('school_uuid','in',$school_uuids)->where('admission_batch','in', $batchname)->where('lowest_rank','>',0)->field('school_uuid,lowest_score as score_min,lowest_rank as weici_min,course_selection_name as subject_group,admission_batch')->order('id asc')->select();
        $list_2_new = $list_2_new_2 = [];
        foreach($list_2 as $k=>$v){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($v['weici_min']) && is_numeric($v['weici_min'])){
                    $dengxiao_weicha = $v['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }
            //院校线差
            if(empty($batch_score2)){
                $linecha_s2 = '-';
            }else{
                if(!empty($v['score_min']) && is_numeric($v['score_min'])){
                    $linecha_s2 = $v['score_min']-$batch_score2;
                }else{
                    $linecha_s2 = '-';
                }
            }
            //$list_2[$k]['dengxiao_weicha'] = $dengxiao_weicha;
            $v['dengxiao_weicha'] = $dengxiao_weicha;
            $v['linecha'] = $linecha_s2;
            if(!empty($v['subject_group'])){
                $v['subject_group'] = filter_subject_group($v['subject_group']);
            }
            $list_2_new[$v['school_uuid'].$v['admission_batch'].$v['subject_group']] = $v;
            $list_2_new_2[$v['school_uuid']] = $v;
        }

        //获取去年院校下的专业的招生计划
        $plan_list = Db::name("school_plan_new")->where('province_id',$province_id)->where('year',$year)->where('type',$type)->where('school_uuid','in',$school_uuids)->where('enrollment_numbers','>',0)->field('school_uuid,college_major_code,college_major_name,enrollment_numbers')->order('id asc')->select();
        $plan_list_new = [];
        foreach($plan_list as $kp=>$vp){
            $plan_list_new[$vp['school_uuid']][] = $vp;
        }
        //dump($plan_list_new);die;

        //23年专业数据
        $major_list_1 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year1)->where('type_name',$type1)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        //23年招生计划
        $plan_list_1 = Db::name("school_plan_new")->where('province_id',$province_id)->where('year',$year1)->where('type',$type1)->where('school_uuid','in',$school_uuids)->where('enrollment_numbers','>',0)->field('school_uuid,school_name,college_major_code,college_major_name,enrollment_numbers')->order('id asc')->select();
        $plan_list_new_1 = [];
        foreach($plan_list_1 as $kp=>$vp){
            $plan_list_new_1[$vp['school_uuid']][] = $vp;
        }//dump($plan_list_new_1);die;
        $major_list_new_1 = [];
        foreach($major_list_1 as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }
            if(empty($batch_score)){
                $linecha = '-';
            }else{
                if(!empty($vm['score_min']) && is_numeric($vm['score_min'])){
                    $linecha = $vm['score_min']-$batch_score;
                }else{
                    $linecha = '-';
                }
            }
            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = $linecha;
            $vm['plan_nums'] = '-';
            $major_list_new_1[$vm['school_uuid']][] = $vm;
        }
        //22年专业数据
        $major_list_2 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year2)->where('type_name',$type2)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        //22年招生计划
        $plan_list_2 = Db::name("school_plan_new")->where('province_id',$province_id)->where('year',$year2)->where('type',$type2)->where('school_uuid','in',$school_uuids)->where('enrollment_numbers','>',0)->field('school_uuid,college_major_code,college_major_name,enrollment_numbers')->order('id asc')->select();
        $plan_list_new_2 = [];
        foreach($plan_list_2 as $kp=>$vp){
            $plan_list_new_2[$vp['school_uuid']][] = $vp;
        }
        $major_list_new_2 = [];
        foreach($major_list_2 as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }
            if(empty($batch_score)){
                $linecha = '-';
            }else{
                if(!empty($vm['score_min']) && is_numeric($vm['score_min'])){
                    $linecha = $vm['score_min']-$batch_score;
                }else{
                    $linecha = '-';
                }
            }
            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = $linecha;
            $vm['plan_nums'] = '-';
            $major_list_new_2[$vm['school_uuid']][] = $vm;
        }

        foreach($list as $kt=>$vt){
            //去年院校线差
            if(empty($batch_score)){
                $linecha_s = '-';
            }else{
                if(!empty($vt['score_min']) && is_numeric($vt['score_min'])){
                    $linecha_s = $vt['score_min']-$batch_score;
                }else{
                    $linecha_s = '-';
                }
            }
            $list[$kt]['linecha'] = $linecha_s;
            //匹配23年院校数据
            if(!empty($vt['subject_group'])){
                $vt['subject_group'] = filter_subject_group($vt['subject_group']);
            }
            if(!empty($list_1_new[$vt['school_uuid'].$vt['admission_batch'].$vt['subject_group']])){
                $school_new_1 = $list_1_new[$vt['school_uuid'].$vt['admission_batch'].$vt['subject_group']];
            }else{
                if(!empty($list_1_new_1[$vt['school_uuid']])){
                    $school_new_1 = $list_1_new_1[$vt['school_uuid']];
                }else{
                    $school_new_1 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                }
            }

            //匹配22年院校数据
            if(!empty($list_2_new[$vt['school_uuid'].$vt['admission_batch'].$vt['subject_group']])){
                $school_new_2 = $list_2_new[$vt['school_uuid'].$vt['admission_batch'].$vt['subject_group']];
            }else{
                if(!empty($list_2_new_2[$vt['school_uuid']])){
                    $school_new_2 = $list_2_new_2[$vt['school_uuid']];
                }else{
                    $school_new_2 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                }
            }
            $list[$kt]['score_min_1'] = $school_new_1['score_min']??'-';
            $list[$kt]['weici_min_1'] = $school_new_1['weici_min']??'-';
            $list[$kt]['linecha_1'] = $school_new_1['linecha']??'-';
            $list[$kt]['dengxiao_weicha_1'] = $school_new_1['dengxiao_weicha']??'-';
            $list[$kt]['score_min_2'] = $school_new_2['score_min']??'-';
            $list[$kt]['weici_min_2'] = $school_new_2['weici_min']??'-';
            $list[$kt]['linecha_2'] = $school_new_2['linecha']??'-';
            $list[$kt]['dengxiao_weicha_2'] = $school_new_2['dengxiao_weicha']??'-';
            //dump($list[$kt]);die;
            //处理专业
            foreach($list[$kt]['major_list'] as $km=>$vm){
                //匹配去年专业招生计划
                $plan_list_new_tem = !empty($plan_list_new[$vt['school_uuid']])?$plan_list_new[$vt['school_uuid']]:[];
                $list[$kt]['major_list'][$km]['plan_nums'] = search_plan_like_major($plan_list_new_tem,$vm['major_name'],$vt['school_uuid']);
                //计算去年专业线差
                if(empty($batch_score)){
                    $linecha = '-';
                }else{
                    if(!empty($vm['score_min']) && is_numeric($vm['score_min'])){
                        $linecha = $vm['score_min']-$batch_score;
                    }else{
                        $linecha = '-';
                    }
                }
                $list[$kt]['major_list'][$km]['linecha'] = $linecha;
                //处理专业因新的一年没有数据，读取的上一年的，$year1，佩佩加
                if($vm['year'] == $year1){
                    $list[$kt]['major_list'][$km]['score_min'] = '-';
                    $list[$kt]['major_list'][$km]['weici_min'] = '-';
                    $list[$kt]['major_list'][$km]['dengxiao_weicha'] = '-';
                    $list[$kt]['major_list'][$km]['linecha'] = '-';
                }

                //匹配23年专业数据
                $marjor_new_1 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                if(!empty($major_list_new_1[$vt['school_uuid']])){
                    $marjor_new_1 = search_major_like($major_list_new_1[$vt['school_uuid']],$vm['major_name']);
                }
                //匹配23年计划
                $plan_list_new_tem_1 = !empty($plan_list_new_1[$vt['school_uuid']])?$plan_list_new_1[$vt['school_uuid']]:[];
                $marjor_new_1['plan_nums'] = search_plan_like_major($plan_list_new_tem_1,$vm['major_name'],$vt['school_uuid']);
                $list[$kt]['major_list'][$km]['score_min_1'] = $marjor_new_1['score_min'];
                $list[$kt]['major_list'][$km]['weici_min_1'] = $marjor_new_1['weici_min'];
                $list[$kt]['major_list'][$km]['dengxiao_weicha_1'] = $marjor_new_1['dengxiao_weicha'];
                $list[$kt]['major_list'][$km]['linecha_1'] = $marjor_new_1['linecha'];
                $list[$kt]['major_list'][$km]['plan_nums_1'] = $marjor_new_1['plan_nums']??'-';

                //匹配22年专业数据
                $marjor_new_2 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                if(!empty($major_list_new_2[$vt['school_uuid']])){
                    $marjor_new_2 = search_major_like($major_list_new_2[$vt['school_uuid']],$vm['major_name']);
                }
                //匹配22年计划
                $plan_list_new_tem_2 = !empty($plan_list_new_2[$vt['school_uuid']])?$plan_list_new_2[$vt['school_uuid']]:[];
                $marjor_new_2['plan_nums'] = search_plan_like_major($plan_list_new_tem_2,$vm['major_name'],$vm['school_uuid']);
                $list[$kt]['major_list'][$km]['score_min_2'] = $marjor_new_2['score_min'];
                $list[$kt]['major_list'][$km]['weici_min_2'] = $marjor_new_2['weici_min'];
                $list[$kt]['major_list'][$km]['dengxiao_weicha_2'] = $marjor_new_2['dengxiao_weicha'];
                $list[$kt]['major_list'][$km]['linecha_2'] = $marjor_new_2['linecha'];
                $list[$kt]['major_list'][$km]['plan_nums_2'] = $marjor_new_2['plan_nums']??'-';



            }

        }
        //dump($list);die;
        $data = array('level_nums'=>$level_nums,'list'=>$list,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);
        //return $this->show(1,"成功", $data);

        Cache('level_nums_'.$user_id,$level_nums);
        return $this->return_json(1,"成功", $data);

    }
    //填报志愿
    public function get_school_list2()
    {
        //$start_time = microtime(true);//计时

        $user_id = $this->user_id;
        $province_id = $this->province_id;
        $pagesize = 10;
        $page = $this->request->get("page",1,'intval');
        $level = $this->request->get("level",0,'intval');
        $batch= $this->request->get("batch",1,'intval');
        if(empty($batch)){
            return $this->show(2001,"缺少参数batch!", '');
        }
        $member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title,cj_rank,cj_subject_mode_title_2024,cj_subject_mode_title_2023')->where('id',$user_id)->find();
        if(empty($member['cj_rank'])){
            return $this->show(2001,"请先创建成绩", '');
        }
        $type = $type1 = $type2= $member['cj_subject_mode_title'];

        $score_min = $this->request->get("score_min",0,'intval');
        $score_max = $this->request->get("score_max",0,'intval');
        $province_ids= $this->request->get("province_ids",'','trim');
        $school_type= $this->request->get("school_type",'','trim');
        $school_tese= $this->request->get("school_tese",'','trim');
        $school_xingzhi= $this->request->get("school_xingzhi",'','trim');
        $school_ids_1= $this->request->get("school_ids",'','trim');
        $cate_ids = $this->request->get("cate_ids",'','trim');
        $major_ids = $this->request->get("major_ids",'','trim');


        if(empty($score_min)){
            $score_min = $member['cj_score']-30;
        }
        if(empty($score_max)){
            $score_max = $member['cj_score']+20;
        }
        if($score_min<$member['cj_score']-50){
            return $this->show(2001,"最低分".($member['cj_score']-50), '');
        }
        if($score_max>$member['cj_score']+50){
            return $this->show(2001,"最高分".($member['cj_score']+50), '');
        }


        $major_ids1 = [];
        $major_ids = explode(',',$major_ids);
        if(!empty($cate_ids)){
            $major_ids1 = Db::name("major")->where('cate_level',3)->where('cate_pid','in',$cate_ids)->column('id');
        }
        $major_ids = array_filter(array_unique(array_merge($major_ids,$major_ids1)));
        $major_school_ids = [];
        if(!empty($major_ids)){
            foreach($major_ids as $km=>$vm){
                $major_school_id = Db::name('school_major_data')->where('FIND_IN_SET(:id,major_ids)',['id' => $vm])->column('school_id');
                $major_school_ids = array_merge($major_school_ids,$major_school_id);

            }
        }
        //dump($major_ids);die;

        if(!empty($province_ids)){
            $map['province_id'] = ['in',$province_ids];
        }
        if(!empty($school_type)){
            $school_id1 = Db::name('school')->where('school_type','in',$school_type)->column('id');
        }else{
            $school_id1 = Db::name('school')->column('id');
        }
        if(!empty($school_tese)){
            $school_id2 = Db::name('school_tese_data')->where('tese_id','in',$school_tese)->column('school_id');
        }else{
            $school_id2 = Db::name('school')->column('id');
        }
        if(!empty($school_xingzhi)){
            $school_id3 = Db::name('school')->where('school_xingzhi','in',$school_xingzhi)->column('id');
        }else{
            $school_id3 = Db::name('school')->column('id');
        }
        $school_ids = array_intersect($school_id1,$school_id2,$school_id3);
        if(!empty($major_school_ids)){
            $school_ids = array_intersect($school_ids,$major_school_ids);
        }

        $map['id'] = ['in',$school_ids];
        $map['status'] = 1;
        $school_ids_ed = Db::name("school")->where($map)->column('id');
        if(!empty($school_ids_1)){
            $school_ids_1 = explode(',',$school_ids_1);
            $school_ids_ed = array_filter(array_unique(array_merge($school_ids_ed,$school_ids_1)));
        }
        $school_list = Db::name("school")->where('id','in',$school_ids_ed)->field('school_uuid,id,school_suoshu,college_code,school_type')->select();
        $school_uuids_ed = array_column($school_list,'school_uuid');

        if($batch == 1){
            $batchname = SchoolModel::getBenkeBtachs();
            $batch_score_name = '本科,本二,1段';
        }elseif($batch == 2){
            $batchname = SchoolModel::getZhuankeBtachs();
            $batch_score_name = '专科,2段';
        }else{
            return $this->show(2001,"参数batch错误!", '');
        }
        $year = date('Y',strtotime("-1 year"));
        $year1 = date('Y',strtotime("-2 year"));
        $year2 = date('Y',strtotime("-3 year"));
        if($year < 2025){
            $type = $member['cj_subject_mode_title_2024'];
        }
        if($year1 < 2024){
            $type1 = $member['cj_subject_mode_title_2023'];
        }
        if($year2 < 2024){
            $type2 = $member['cj_subject_mode_title_2023'];
        }
        $batch_score = Db::name("batch_line")->where('batch_name','in',$batch_score_name)->where('province_id',$province_id)->where('year',$year)->value('socre');//批次分数
        $batch_score1 = Db::name("batch_line")->where('batch_name','in',$batch_score_name)->where('province_id',$province_id)->where('year',$year1)->value('socre');//批次分数
        $batch_score2 = Db::name("batch_line")->where('batch_name','in',$batch_score_name)->where('province_id',$province_id)->where('year',$year2)->value('socre');//批次分数
        if(cache('school_'.$user_id)){
            $data = cache('school_'.$user_id);
        }else{
            //$data = $this->get_data_cache($user_id,$province_id);

            $result = ZhiyuanService::get_data_cache($user_id,$province_id);
            if($result[0] != 200){
                return $this->show(2002,$result[1]??'error', '');
            }
            $data = $result[1];

            Cache('school_'.$user_id,$data);
        }

        foreach($data as $k=>$v){
            if(!in_array($v['school_uuid'],$school_uuids_ed)){
                unset($data[$k]);
                continue;
            }
            $batchnames = explode(',',$batchname);
            if(!in_array($v['admission_batch'],$batchnames)){
                unset($data[$k]);
                continue;
            }
            if(!empty($score_min)){
                if($v['score_min']<$score_min-1){
                    unset($data[$k]);
                    continue;
                }
            }
            if(!empty($score_max)){
                if($v['score_min']>$score_max+1){
                    unset($data[$k]);
                    continue;
                }
            }
            //院校线差
            /*if(empty($batch_score)){
                $linecha_s = '-';
            }else{
                if(!empty($v['score_min']) && is_numeric($v['score_min'])){
                    $linecha_s = $v['score_min']-$batch_score;
                }else{
                    $linecha_s = '-';
                }
            }
            if(empty($batch_score1)){
                $linecha_s1 = '-';
            }else{
                if(!empty($v['score_min_1']) && is_numeric($v['score_min_1'])){
                    $linecha_s1 = $v['score_min_1']-$batch_score1;
                }else{
                    $linecha_s1 = '-';
                }
            }
            if(empty($batch_score2)){
                $linecha_s2 = '-';
            }else{
                if(!empty($v['score_min_2']) && is_numeric($v['score_min_2'])){
                    $linecha_s2 = $v['score_min_2']-$batch_score2;
                }else{
                    $linecha_s2 = '-';
                }
            }
            $data[$k]['linecha_1'] = $linecha_s1;
            $data[$k]['linecha_2'] = $linecha_s2;*/

            $major_list = $v['major_list'];
            foreach($major_list as $km=>$vm){
                if(!in_array($vm['batch_name'],$batchnames)){
                    unset($major_list[$km]);
                    continue;
                }
                //专业线差
                /*if(empty($batch_score)){
                    $linecha = '-';
                }else{
                    if(!empty($vm['score_min']) && is_numeric($vm['score_min'])){
                        $linecha = $vm['score_min']-$batch_score;
                    }else{
                        $linecha = '-';
                    }
                }
                $major_list[$km]['linecha'] = $linecha;*/
            }
            //if(empty($major_list)){
            //	unset($data[$k]);
            //	continue;
            //}
            $data[$k]['major_list'] = $major_list;
        }

        $all_nums = 0;
        $chong_nums = 0;
        $wen_nums = 0;
        $bao_nums = 0;
        $data_level = [];
        foreach($data as $k=>$v){
            $dengxiao_weicha = $v['dengxiao_weicha'];
            if($dengxiao_weicha>4000){//大于75%
                $bao_nums++;
                if($level==3){
                    $data_level[] = $v;
                }
            }elseif($dengxiao_weicha>-1 && $dengxiao_weicha<=4000){//大于46%,小于等于75%，
                $wen_nums++;
                if($level==2){
                    $data_level[] = $v;
                }
            }else{
                $chong_nums++;
                if($level==1){
                    $data_level[] = $v;
                }
            }
            $all_nums++;
        }
        $level_nums = array('all_nums'=>$all_nums,'chong_nums'=>$chong_nums,'wen_nums'=>$wen_nums,'bao_nums'=>$bao_nums);

        if($level>0){
            $data = $data_level;
        }

        $count = count($data);
        $pages = ceil($count/$pagesize);
        $start = ($page - 1) * $pagesize;
        $list = array_slice($data, $start, $pagesize);

        //对当前页10条数据进行处理
        //23年院校数据
        $school_uuids = array_column($list,'school_uuid');
        //dump($school_uuids);
        //$score_min = $member['cj_score']-50;
        //$score_max = $member['cj_score']+50;
        $list_1 = Db::name("school_line_new")->where('province_id',$province_id)->where('year',$year1)->where('type_name',$type1)->where('school_uuid','in',$school_uuids)->where('admission_batch','in', $batchname)->where('lowest_rank','>',0)->field('school_uuid,lowest_score as score_min,lowest_rank as weici_min,course_selection_name as subject_group,admission_batch')->order('id asc')->select();
        //echo Db::name("school_line_new")->getlastsql();die;
        $list_1_new = $list_1_new_1 = [];
        foreach($list_1 as $k=>$v){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($v['weici_min']) && is_numeric($v['weici_min'])){
                    $dengxiao_weicha = $v['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }
            //院校线差
            if(empty($batch_score1)){
                $linecha_s1 = '-';
            }else{
                if(!empty($v['score_min']) && is_numeric($v['score_min'])){
                    $linecha_s1 = $v['score_min']-$batch_score1;
                }else{
                    $linecha_s1 = '-';
                }
            }
            //$list_1[$k]['dengxiao_weicha'] = $dengxiao_weicha;
            $v['dengxiao_weicha'] = $dengxiao_weicha;
            $v['linecha'] = $linecha_s1;
            if(!empty($v['subject_group'])){
                $v['subject_group'] = filter_subject_group($v['subject_group']);
            }
            $list_1_new[$v['school_uuid'].$v['admission_batch'].$v['subject_group']] = $v;
            $list_1_new_1[$v['school_uuid']] = $v;
        }

        //dump($list);
        //dump($list_1_new); die;
        //22年院校数据
        $list_2 = Db::name("school_line_new")->where('province_id',$province_id)->where('year',$year2)->where('type_name',$type2)->where('school_uuid','in',$school_uuids)->where('admission_batch','in', $batchname)->where('lowest_rank','>',0)->field('school_uuid,lowest_score as score_min,lowest_rank as weici_min,course_selection_name as subject_group,admission_batch')->order('id asc')->select();
        $list_2_new = $list_2_new_2 = [];
        foreach($list_2 as $k=>$v){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($v['weici_min']) && is_numeric($v['weici_min'])){
                    $dengxiao_weicha = $v['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }
            //院校线差
            if(empty($batch_score2)){
                $linecha_s2 = '-';
            }else{
                if(!empty($v['score_min']) && is_numeric($v['score_min'])){
                    $linecha_s2 = $v['score_min']-$batch_score2;
                }else{
                    $linecha_s2 = '-';
                }
            }
            //$list_2[$k]['dengxiao_weicha'] = $dengxiao_weicha;
            $v['dengxiao_weicha'] = $dengxiao_weicha;
            $v['linecha'] = $linecha_s2;
            if(!empty($v['subject_group'])){
                $v['subject_group'] = filter_subject_group($v['subject_group']);
            }
            $list_2_new[$v['school_uuid'].$v['admission_batch'].$v['subject_group']] = $v;
            $list_2_new_2[$v['school_uuid']] = $v;
        }

        //获取去年院校下的专业的招生计划
        $plan_list = Db::name("school_plan_new")->where('province_id',$province_id)->where('year',$year)->where('type',$type)->where('school_uuid','in',$school_uuids)->where('enrollment_numbers','>',0)->field('school_uuid,college_major_code,college_major_name,enrollment_numbers')->order('id asc')->select();
        $plan_list_new = [];
        foreach($plan_list as $kp=>$vp){
            $plan_list_new[$vp['school_uuid']][] = $vp;
        }
        //dump($plan_list_new);die;

        //23年专业数据
        $major_list_1 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year1)->where('type_name',$type1)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        //23年招生计划
        $plan_list_1 = Db::name("school_plan_new")->where('province_id',$province_id)->where('year',$year1)->where('type',$type1)->where('school_uuid','in',$school_uuids)->where('enrollment_numbers','>',0)->field('school_uuid,school_name,college_major_code,college_major_name,enrollment_numbers')->order('id asc')->select();
        $plan_list_new_1 = [];
        foreach($plan_list_1 as $kp=>$vp){
            $plan_list_new_1[$vp['school_uuid']][] = $vp;
        }//dump($plan_list_new_1);die;
        $major_list_new_1 = [];
        foreach($major_list_1 as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }
            if(empty($batch_score)){
                $linecha = '-';
            }else{
                if(!empty($vm['score_min']) && is_numeric($vm['score_min'])){
                    $linecha = $vm['score_min']-$batch_score;
                }else{
                    $linecha = '-';
                }
            }
            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = $linecha;
            $vm['plan_nums'] = '-';
            $major_list_new_1[$vm['school_uuid']][] = $vm;
        }
        //22年专业数据
        $major_list_2 = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year2)->where('type_name',$type2)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        //22年招生计划
        $plan_list_2 = Db::name("school_plan_new")->where('province_id',$province_id)->where('year',$year2)->where('type',$type2)->where('school_uuid','in',$school_uuids)->where('enrollment_numbers','>',0)->field('school_uuid,college_major_code,college_major_name,enrollment_numbers')->order('id asc')->select();
        $plan_list_new_2 = [];
        foreach($plan_list_2 as $kp=>$vp){
            $plan_list_new_2[$vp['school_uuid']][] = $vp;
        }
        $major_list_new_2 = [];
        foreach($major_list_2 as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }
            if(empty($batch_score)){
                $linecha = '-';
            }else{
                if(!empty($vm['score_min']) && is_numeric($vm['score_min'])){
                    $linecha = $vm['score_min']-$batch_score;
                }else{
                    $linecha = '-';
                }
            }
            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = $linecha;
            $vm['plan_nums'] = '-';
            $major_list_new_2[$vm['school_uuid']][] = $vm;
        }

        foreach($list as $kt=>$vt){
            //去年院校线差
            if(empty($batch_score)){
                $linecha_s = '-';
            }else{
                if(!empty($vt['score_min']) && is_numeric($vt['score_min'])){
                    $linecha_s = $vt['score_min']-$batch_score;
                }else{
                    $linecha_s = '-';
                }
            }
            $list[$kt]['linecha'] = $linecha_s;
            //匹配23年院校数据
            if(!empty($vt['subject_group'])){
                $vt['subject_group'] = filter_subject_group($vt['subject_group']);
            }
            if(!empty($list_1_new[$vt['school_uuid'].$vt['admission_batch'].$vt['subject_group']])){
                $school_new_1 = $list_1_new[$vt['school_uuid'].$vt['admission_batch'].$vt['subject_group']];
            }else{
                if(!empty($list_1_new_1[$vt['school_uuid']])){
                    $school_new_1 = $list_1_new_1[$vt['school_uuid']];
                }else{
                    $school_new_1 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                }
            }

            //匹配22年院校数据
            if(!empty($list_2_new[$vt['school_uuid'].$vt['admission_batch'].$vt['subject_group']])){
                $school_new_2 = $list_2_new[$vt['school_uuid'].$vt['admission_batch'].$vt['subject_group']];
            }else{
                if(!empty($list_2_new_2[$vt['school_uuid']])){
                    $school_new_2 = $list_2_new_2[$vt['school_uuid']];
                }else{
                    $school_new_2 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                }
            }
            $list[$kt]['score_min_1'] = $school_new_1['score_min']??'-';
            $list[$kt]['weici_min_1'] = $school_new_1['weici_min']??'-';
            $list[$kt]['linecha_1'] = $school_new_1['linecha']??'-';
            $list[$kt]['dengxiao_weicha_1'] = $school_new_1['dengxiao_weicha']??'-';
            $list[$kt]['score_min_2'] = $school_new_2['score_min']??'-';
            $list[$kt]['weici_min_2'] = $school_new_2['weici_min']??'-';
            $list[$kt]['linecha_2'] = $school_new_2['linecha']??'-';
            $list[$kt]['dengxiao_weicha_2'] = $school_new_2['dengxiao_weicha']??'-';
            //dump($list[$kt]);die;
            //处理专业
            foreach($list[$kt]['major_list'] as $km=>$vm){
                //匹配去年专业招生计划
                $plan_list_new_tem = !empty($plan_list_new[$vt['school_uuid']])?$plan_list_new[$vt['school_uuid']]:[];
                $list[$kt]['major_list'][$km]['plan_nums'] = search_plan_like_major($plan_list_new_tem,$vm['major_name'],$vt['school_uuid']);
                //计算去年专业线差
                if(empty($batch_score)){
                    $linecha = '-';
                }else{
                    if(!empty($vm['score_min']) && is_numeric($vm['score_min'])){
                        $linecha = $vm['score_min']-$batch_score;
                    }else{
                        $linecha = '-';
                    }
                }
                $list[$kt]['major_list'][$km]['linecha'] = $linecha;

                //匹配23年专业数据
                $marjor_new_1 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                if(!empty($major_list_new_1[$vt['school_uuid']])){
                    $marjor_new_1 = search_major_like($major_list_new_1[$vt['school_uuid']],$vm['major_name']);
                }
                //匹配23年计划
                $plan_list_new_tem_1 = !empty($plan_list_new_1[$vt['school_uuid']])?$plan_list_new_1[$vt['school_uuid']]:[];
                $marjor_new_1['plan_nums'] = search_plan_like_major($plan_list_new_tem_1,$vm['major_name'],$vt['school_uuid']);
                $list[$kt]['major_list'][$km]['score_min_1'] = $marjor_new_1['score_min'];
                $list[$kt]['major_list'][$km]['weici_min_1'] = $marjor_new_1['weici_min'];
                $list[$kt]['major_list'][$km]['dengxiao_weicha_1'] = $marjor_new_1['dengxiao_weicha'];
                $list[$kt]['major_list'][$km]['linecha_1'] = $marjor_new_1['linecha'];
                $list[$kt]['major_list'][$km]['plan_nums_1'] = $marjor_new_1['plan_nums']??'-';

                //匹配22年专业数据
                $marjor_new_2 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                if(!empty($major_list_new_2[$vt['school_uuid']])){
                    $marjor_new_2 = search_major_like($major_list_new_2[$vt['school_uuid']],$vm['major_name']);
                }
                //匹配22年计划
                $plan_list_new_tem_2 = !empty($plan_list_new_2[$vt['school_uuid']])?$plan_list_new_2[$vt['school_uuid']]:[];
                $marjor_new_2['plan_nums'] = search_plan_like_major($plan_list_new_tem_2,$vm['major_name'],$vm['school_uuid']);
                $list[$kt]['major_list'][$km]['score_min_2'] = $marjor_new_2['score_min'];
                $list[$kt]['major_list'][$km]['weici_min_2'] = $marjor_new_2['weici_min'];
                $list[$kt]['major_list'][$km]['dengxiao_weicha_2'] = $marjor_new_2['dengxiao_weicha'];
                $list[$kt]['major_list'][$km]['linecha_2'] = $marjor_new_2['linecha'];
                $list[$kt]['major_list'][$km]['plan_nums_2'] = $marjor_new_2['plan_nums']??'-';



            }

        }
        //dump($list);die;
        $data = array('level_nums'=>$level_nums,'list'=>$list,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);
        //return $this->show(1,"成功", $data);

        Cache('level_nums_'.$user_id,$level_nums);
        return $this->return_json(1,"成功", $data);

    }

    //保存院校缓存数据
    public function save_school_cache()
    {

        $user_id = $this->user_id;
        $province_id = $this->province_id;

        //$data = $this->get_data_cache($user_id,$province_id);

        $result = ZhiyuanService::get_data_cache($user_id,$province_id);
        if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
        }
        $data = $result[1];

        Cache('school_'.$user_id,$data);
        return $this->show(1,"缓存成功");

    }

    //此方法移到服务里了
    public function get_data_cache($user_id,$province_id)
    {
        //$a = Db::connect(config('database'))->table('think_school')->find();
        //dump($a);die;
        //$start_time = microtime(true);//计时

        //$user_id = $this->user_id;
        //$province_id = $this->province_id;


        $enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
        $year = date('Y',strtotime("-1 year"));
        $member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title,cj_rank,cj_subject_mode_title_2024,cj_subject_mode_title_2023')->where('id',$user_id)->find();
        $score_min = $member['cj_score']-50;
        $score_max = $member['cj_score']+50;
        if(empty($member['cj_rank'])){
            return $this->show(2001,"请先创建成绩", '');
        }
        //$type = $member['cj_subject_mode_title'];
        //if($year < 2025){
        //	$type = $member['cj_subject_mode_title_2024'];
        //}
        $type = $member['cj_subject_mode_title_2024'];
        //dump($enrollprovince);dump($score_min);dump($score_max);dump($type);die;

        //去年院校数据
        $list = Db::name("school_line_new")->where('province_id',$province_id)->where('year',$year)->where('type_name',$type)->where('lowest_rank','>',0)->whereBetween('lowest_score', [$score_min,$score_max])->field('id,school_uuid,college_name,cover_image,school_type as school_xingzhi,province,school_in_city as city,course_selection_name as subject_group,lowest_score as score_min,lowest_rank as weici_min,admission_batch')->order('id asc')->select();
        $school_uuids = array_column($list,'school_uuid');

        $school_list = Db::name("school")->field('school_uuid,id,school_suoshu,college_code,school_type')->where('school_uuid','in',$school_uuids)->select();
        $school_ids = array_column($school_list,'id');
        $school_suoshu_ed = array_column($school_list,'school_suoshu','school_uuid');
        $school_id_ed = array_column($school_list,'id','school_uuid');
        $school_type_ed = array_column($school_list,'school_type','school_uuid');
        $school_code_ed = array_column($school_list,'college_code','school_uuid');
        $school_tese = Db::name('school_tese_data')->alias('d')->join('school_tese t','d.tese_id=t.id')->where('d.school_id','in',$school_ids)->field('d.school_id,t.title')->select();
        $school_tese_new = [];
        foreach($school_tese as $kt=>$vt){
            $school_tese_new[$vt['school_id']][] = $vt['title'];

        }
        $school_type_arr = Db::name('school_type')->column('id,title');
        $suoshu_list = SchoolModel::getSuoshuList();

        $year1 = date('Y',strtotime("-2 year"));
        $year2 = date('Y',strtotime("-3 year"));
        //23年院校数据
        /*$list_1 = Db::name("school_line_new")->where('province_id',$province_id)->where('year',$year1)->where('type_name',$type)->where('lowest_rank','>',0)->whereBetween('lowest_score', [$score_min,$score_max])->field('school_uuid,lowest_score as score_min,lowest_rank as weici_min,course_selection_name as subject_group')->order('id asc')->select();
        $list_1_new = [];
        foreach($list_1 as $k=>$v){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($v['weici_min']) && is_numeric($v['weici_min'])){
                    $dengxiao_weicha = $v['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }
            //$list_1[$k]['dengxiao_weicha'] = $dengxiao_weicha;
            $v['dengxiao_weicha'] = $dengxiao_weicha;
            $list_1_new[$v['school_uuid']][] = $v;
        }
        //22年院校数据
        $list_2 = Db::name("school_line_new")->where('province_id',$province_id)->where('year',$year2)->where('type_name',$type)->where('lowest_rank','>',0)->whereBetween('lowest_score', [$score_min,$score_max])->field('school_uuid,lowest_score as score_min,lowest_rank as weici_min,course_selection_name as subject_group')->order('id asc')->select();
        $list_2_new = [];
        foreach($list_2 as $k=>$v){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($v['weici_min']) && is_numeric($v['weici_min'])){
                    $dengxiao_weicha = $v['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }
            //$list_2[$k]['dengxiao_weicha'] = $dengxiao_weicha;
            $v['dengxiao_weicha'] = $dengxiao_weicha;
            $list_2_new[$v['school_uuid']][] = $v;
        }*/

        //获取去年院校下的专业的招生计划
        //$plan_list = Db::name("school_plan_new")->where('province_id',$province_id)->where('year',$year)->where('type',$type)->where('school_uuid','in',$school_uuids)->field('school_uuid,college_major_code,college_major_name,enrollment_numbers')->order('id asc')->select();
        //$plan_list_new = [];
        //foreach($plan_list as $kp=>$vp){
        //	$plan_list_new[$vp['school_uuid']][] = $vp;
        //}
        //dump($plan_list_new);die;

        //获取去年专业数据
        $score_min1 = $score_min+10;
        $score_max1 = $score_max-10;
        //$major_list = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->where('lowest_section','>',0)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();
        $major_list = Db::name("major_line_new")->where('province_id',$province_id)->where('year',$year)->where('type_name',$type)->where('school_uuid','in',$school_uuids)->whereBetween('lowest_score', [$score_min1,$score_max1])->field('school_uuid,lowest_score as score_min,lowest_section as weici_min,major_name,major_code,batch_name,subject_group')->order('id asc')->select();

        //dump(count($school_uuids));dump(count($major_list));dump(count($plan_list));
        //$end_time = microtime(true);//计时
        //echo "执行时间: " . ($end_time - $start_time) . " 秒";die;

        $major_list_new = [];
        foreach($major_list as $km=>$vm){
            if(empty($member['cj_rank'])){
                $dengxiao_weicha = '-';
            }else{
                if(!empty($vm['weici_min']) && is_numeric($vm['weici_min'])){
                    $dengxiao_weicha = $vm['weici_min']-$member['cj_rank'];
                }else{
                    $dengxiao_weicha = '-';
                }
            }
            //$major_list[$km]['dengxiao_weicha'] = $dengxiao_weicha;
            //$major_list[$km]['linecha'] = '-';
            //$major_list[$km]['plan_nums'] = '-';//search_plan_like_major($plan_list,$vm['major_name'],$vm['school_uuid']);

            $vm['dengxiao_weicha'] = $dengxiao_weicha;
            $vm['linecha'] = '-';
            $vm['plan_nums'] = '-';
            $vm['subject_group'] = filter_subject_group($vm['subject_group']);
            $major_list_new[$vm['school_uuid'].$vm['subject_group'].$vm['batch_name']][] = $vm;
        }
        //$major_list_new = [];
        //foreach($major_list as $km=>$vm){
        //	$major_list_new[$vm['school_uuid']][] = $vm;
        //}
        //dump($major_list_new);die;

        //$end_time = microtime(true);//计时
        //echo "执行时间: " . ($end_time - $start_time) . " 秒";die;
        //dump(count($list));
        if(!empty($list)){
            foreach($list as $k=>$v){
                $school_suoshu = !empty($school_suoshu_ed[$v['school_uuid']])?$school_suoshu_ed[$v['school_uuid']]:'';
                $school_id = !empty($school_id_ed[$v['school_uuid']])?$school_id_ed[$v['school_uuid']]:'';
                $school_tese = !empty($school_tese_new[$school_id])?$school_tese_new[$school_id]:'';
                //$school_type = !empty($school_type_arr[$school_type_ed[$v['school_uuid']]])?$school_type_arr[$school_type_ed[$v['school_uuid']]]:'';
                $school_type = !empty($school_type_ed[$v['school_uuid']])?$school_type_ed[$v['school_uuid']]:'';
                $school_type_title = !empty($school_type_arr[$school_type])?$school_type_arr[$school_type]:'';
                $school_code = !empty($school_code_ed[$v['school_uuid']])?$school_code_ed[$v['school_uuid']]:'';

                if(empty($member['cj_rank'])){
                    $dengxiao_weicha = '-';
                }else{
                    if(!empty($v['weici_min']) && is_numeric($v['weici_min'])){
                        $dengxiao_weicha = $v['weici_min']-$member['cj_rank'];
                    }else{
                        $dengxiao_weicha = '-';
                    }
                }
                $list[$k]['school_code'] = $school_code;
                $list[$k]['school_type'] = $school_type_title;
                $list[$k]['school_suoshu'] = !empty($suoshu_list[$school_suoshu])?$suoshu_list[$school_suoshu]:'';
                $list[$k]['school_tese'] = $school_tese;
                $list[$k]['dengxiao_weicha'] = $dengxiao_weicha;
                $list[$k]['linecha'] = '-';

                //匹配23年和22年的院校数据
                /*$school_new_1 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                foreach($list_1 as $vsl){
                    if($v['school_uuid'] == $vsl['school_uuid'] && $v['subject_group'] == $vsl['subject_group']){
                        $school_new_1 = $vsl;
                        break;
                    }
                }
                $school_new_2 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                foreach($list_2 as $vs2){
                    if($v['school_uuid'] == $vs2['school_uuid'] && $v['subject_group'] == $vs2['subject_group']){
                        $school_new_2 = $vs2;
                        break;
                    }
                }*/
                /*if(!empty($list_1_new[$v['school_uuid']])){
                    $school_new_1 = $list_1_new[$v['school_uuid']];
                }else{
                    $school_new_1 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                }
                if(!empty($list_2_new[$v['school_uuid']])){
                    $school_new_2 = $list_2_new[$v['school_uuid']];
                }else{
                    $school_new_2 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
                }
                $list[$k]['score_min_1'] = $school_new_1['score_min']??'-';
                $list[$k]['weici_min_1'] = $school_new_1['weici_min']??'-';
                $list[$k]['dengxiao_weicha_1'] = $school_new_1['dengxiao_weicha']??'-';
                $list[$k]['score_min_2'] = $school_new_2['score_min']??'-';
                $list[$k]['weici_min_2'] = $school_new_2['weici_min']??'-';
                $list[$k]['dengxiao_weicha_2'] = $school_new_2['dengxiao_weicha']??'-';

                */
                //匹配去年的专业数据
                $v['subject_group'] = filter_subject_group($v['subject_group']);
                if(!empty($major_list_new[$v['school_uuid'].$v['subject_group'].$v['admission_batch']])){
                    $list[$k]['major_list'] = array_unique_two($major_list_new[$v['school_uuid'].$v['subject_group'].$v['admission_batch']]);//咕咕数据有重复的需要去重
                }else{
                    unset($list[$k]);
                }
            }

        }
        //$end_time = microtime(true);//计时
        //echo "执行时间: " . ($end_time - $start_time) . " 秒";die;
        return $list;
    }

    //智能填报页面-获取稳冲保数量(暂时废弃)
    /*public function get_risk_level_nums()
    {
		$user_id = $this->user_id;
		$province_id = $this->province_id;
		
        $batch= $this->request->get("batch",1,'intval');
        if(empty($batch)){
            return $this->show(2001,"缺少参数batch!", '');
        }
        
        $score_min = $this->request->get("score_min",0,'intval'); 
        $score_max = $this->request->get("score_max",0,'intval'); 
        $province_ids= $this->request->get("province_ids",'','trim');
        $school_type= $this->request->get("school_type",'','trim');
        $school_tese= $this->request->get("school_tese",'','trim');
        $school_xingzhi= $this->request->get("school_xingzhi",'','trim'); 
        $school_ids_1= $this->request->get("school_ids",'','trim'); 
        $cate_ids = $this->request->get("cate_ids",'','trim'); 
        $major_ids = $this->request->get("major_ids",'','trim');
		$major_ids1 = [];
		$major_ids = explode(',',$major_ids);
        if(!empty($cate_ids)){
			$major_ids1 = Db::name("major")->where('cate_level',3)->where('cate_pid','in',$cate_ids)->column('id');
        }
		$major_ids = array_filter(array_unique(array_merge($major_ids,$major_ids1)));
		$major_school_ids = [];
		if(!empty($major_ids)){
			foreach($major_ids as $km=>$vm){
				$major_school_id = Db::name('school_major_data')->where('FIND_IN_SET(:id,major_ids)',['id' => $vm])->column('school_id');
				$major_school_ids = array_merge($major_school_ids,$major_school_id);
				
			}
		}
		
        if(!empty($province_ids)){
			$map['province_id'] = ['in',$province_ids];
        }
		if(!empty($school_type)){
			$school_id1 = Db::name('school')->where('school_type','in',$school_xingzhi)->column('id');
        }else{
			$school_id1 = Db::name('school')->column('id');
		}
        if(!empty($school_tese)){
			$school_id2 = Db::name('school_tese_data')->where('tese_id','in',$school_tese)->column('school_id');
        }else{
			$school_id2 = Db::name('school')->column('id');
		}
        if(!empty($school_xingzhi)){
			$school_id3 = Db::name('school')->where('school_xingzhi','in',$school_xingzhi)->column('id');
        }else{
			$school_id3 = Db::name('school')->column('id');
		}
		$school_ids = array_intersect($school_id1,$school_id2,$school_id3);
		if(!empty($major_school_ids)){
			$school_ids = array_intersect($school_ids,$major_school_ids);
        }
		
		$map['id'] = ['in',$school_ids];
		$map['status'] = 1;
		$school_ids_ed = Db::name("school")->where($map)->column('id');
		if(!empty($school_ids_1)){
			$school_ids_1 = explode(',',$school_ids_1);
			$school_ids_ed = array_filter(array_unique(array_merge($school_ids_ed,$school_ids_1))); 
		}
		$school_list = Db::name("school")->where('id','in',$school_ids_ed)->field('school_uuid,id,school_suoshu,college_code,school_type')->select();
       
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$year = date('Y',strtotime("-1 year"));
		$member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title,cj_rank')->where('id',$user_id)->find();
		if(empty($score_min)){
			$score_min = $member['cj_score']-30;
		}
		if(empty($score_max)){
			$score_max = $member['cj_score']+20;
		}
		if($score_min<$member['cj_score']-80){
			return $this->show(2001,"最低分".($member['cj_score']-80), '');
		}
		if($score_max>$member['cj_score']+50){
			return $this->show(2001,"最高分".($member['cj_score']+50), '');
		}
		if(empty($member['cj_rank'])){
			return $this->show(2001,"请先创建成绩", '');
		}
		$type = $member['cj_subject_mode_title'];
		if($batch == 1){
			$batchname = SchoolModel::getBenkeBtachs();
			$batch_score_name = '本科';
		}elseif($batch == 2){
			$batchname = SchoolModel::getZhuankeBtachs();
			$batch_score_name = '专科';
		}else{
			return $this->show(2001,"参数batch错误!", '');
		}
		//$end_time = microtime(true);//计时
		//echo "执行时间: " . ($end_time - $start_time) . " 秒";die;
		//dump($batchname);die;
		$batch_score = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year)->value('socre');//批次分数
		
		//dump($school_uuids_ed);die;
		$map['province'] = $enrollprovince;
		$map['year'] = $year;
		$map['type_name'] = $type;
		$map['lowest_rank'] = ['>',0];
        
		$list = Db::name("school_line")->where($map)->where('admission_batch','in', $batchname)->whereBetween('lowest_score', [$score_min,$score_max])->field('lowest_score as score_min,lowest_rank as weici_min')->order('id asc')->select(); 
		
		$bao_nums = 0;
		$wen_nums = 0;
		$chong_nums = 0;
		foreach($list as $k=>$v){
			 
			$dengxiao_weicha = $v['weici_min']-$member['cj_rank'];
			if($dengxiao_weicha>4000){//大于75%
				$bao_nums++;
			}elseif($dengxiao_weicha>-1 && $dengxiao_weicha<=4000){//大于46%,小于等于75%，
				$wen_nums++;
			}else{
				$chong_nums++;
			}
			
		}
        $data = array('all_nums'=>count($list),'chong_nums'=>$chong_nums,'wen_nums'=>$wen_nums,'bao_nums'=>$bao_nums);	
		return $this->show(1,"成功", $data);
		
    }*/
}